package com.cinco.blog.controller.wx;

import com.cinco.blog.po.Blog;
import com.cinco.blog.service.BlogService;
import com.cinco.blog.service.TagService;
import com.cinco.blog.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wx")
public class MiniProgramController {
    @Autowired
    private BlogService blogService;

    @Autowired
    private TypeService typeService;

    @Autowired
    private TagService tagService;

    @GetMapping("/blogs")
    public Map blogs() {
        List<Blog> blogs = blogService.findAllwx();
        HashMap<String, Object> map = new HashMap<>();
        map.put("blogs", blogs);
        return map;
    }

    @GetMapping("/viewadd/{id}")
    public Map viewadd(@PathVariable Long id) {
        blogService.updateViews(id);
        HashMap<String, Object> map = new HashMap<>();
        map.put("msg","view addsuccess");
        return map;
    }

    @GetMapping("/tags/{id}")
    public Map tags(@PathVariable Long id){
        HashMap<String, Object> map = new HashMap<>();
        map.put("tagName",tagService.getTag(id).getName());
        return map;
    }

    @GetMapping("/blog/{id}")
    public Map blog(@PathVariable Long id){
        HashMap<String, Object> map = new HashMap<>();
        map.put("blog",blogService.getBlogWx(id));
        return map;
    }
}
